//
//  ScanQRCodeToGetPasswordViewController.m
//  GetPowerDBO
//
//  Created by 周博 on 2017/8/1.
//  Copyright © 2017年 BogoZhou. All rights reserved.
//

#import "ScanQRCodeToGetPasswordViewController.h"
#import "BorderHelper.h"
#import "GetPasswordAgainViewController.h"

@interface ScanQRCodeToGetPasswordViewController ()<GetPasswordAgainViewControllerDelegate>
{
    
}
@property (nonatomic,strong) NSArray *labelsArray;
@end

@implementation ScanQRCodeToGetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self UISetting];
    [self getPassowrdFirstTime];
}

- (void)UISetting{
    [BorderHelper setOnlyUnderLineColor:kColorFrom0x(0x8b8b8b) view:_labelPasswordError];
    
    _labelsArray = @[_label1,_label2,_label3,_label4,_label5,_label6];
}

#pragma mark - 网络请求
- (void)getPassowrdFirstTime{
    [self.hub hideAnimated:YES];
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    // Set the label text.
    self.hub.label.text = NSLocalizedString(@"加载中...", @"HUD loading title");
    [[AFClient shareInstance] powerGetPasswordFirstTimeByEid:kUserId alias:_aliasNum progressBlock:nil success:^(id responseBody) {
        [self.hub hideAnimated:YES];

        if ([responseBody[@"code"] integerValue] == 200) {
            NSArray *array = responseBody[@"data"];
            for (NSInteger i = 0; i < array.count; i ++) {
                UILabel *label = _labelsArray[i];
                label.text = [NSString stringWithFormat:@"%@",array[i]];
            }
            NSLog(@"%@",array);
        }else{
            [self alertVCByTitle:responseBody[@"message"]];
        }
    } failure:^(NSError *error) {
        [self.hub hideAnimated:YES];
    }];
}

- (void)getPasswordAgainByStepNum:(NSString *)stepNum{
    [self.hub hideAnimated:YES];
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    // Set the label text.
    self.hub.label.text = NSLocalizedString(@"加载中...", @"HUD loading title");
    [[AFClient shareInstance] powerGetPasswordAgainByEid:kUserId alias:_aliasNum step:stepNum progressBlock:nil success:^(id responseBody) {
        [self.hub hideAnimated:YES];

        if ([responseBody[@"code"] integerValue] == 200) {
            NSArray *array = responseBody[@"data"];
            for (NSInteger i = 0; i < array.count; i ++) {
                UILabel *label = _labelsArray[i];
                label.text = [NSString stringWithFormat:@"%@",array[i]];
            }
            NSLog(@"%@",array);
        }else{
            [self alertVCByTitle:responseBody[@"message"]];
        }
    } failure:^(NSError *error) {
        [self.hub hideAnimated:YES];
    }];
}

#pragma mark - 点击事件
//返回主页面
- (IBAction)backButtonClick:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

//点击密码错误
- (IBAction)passwordErrorButtonClick:(UIButton *)sender {
    UIStoryboard *storyboard = kMainStroyboard;
    GetPasswordAgainViewController *jumpView = [storyboard instantiateViewControllerWithIdentifier:@"GetPasswordAgainViewController"];
    jumpView.delegate = self;
    jumpView.modalPresentationStyle = UIModalPresentationOverFullScreen;
    [self presentViewController:jumpView animated:NO completion:nil];
}



- (void)alertVCByTitle:(NSString *)title{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - getStepNumDelegate

- (void)getStepNum:(NSString *)stepNum{
    [self getPasswordAgainByStepNum:stepNum];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
